<?php

namespace App\Http\Controllers\Admin\RoomManager;

use App\Exceptions\BasicException;
use App\Http\Controllers\BaseController;
use Illuminate\Http\Request;    //引用http请求类
use App\Response\Response;

class StatisticController extends BaseController {

    /**
     * @api {get} /room/statistic 房间流水统计-列表
     * @apiVersion 0.1.0
     * @apiName 房间管理-房间流水统计-列表
     * @apiGroup 房间管理
     *
     * @apiParam {string} start_time 开始时间 必传
     * @apiParam {string} end_time 结束时间 必传
     * @apiParam {number} label_id 标签id 必传
     *
     *
     * @apiSuccessExample 成功响应
     *
     *
    {
    "code": 200,
    "data": {
        "income_list": [
            {
                "total(流水)": "15276239857.00",
                "room_name(房间名称)": "安卓房间1???????",
                "room_id(房间编号)": 11,
                "date(日期)": "2020-11-01~2020-12-16"
            }
        ],
        "new_list": [
            {
                "total(新人消费人数)": 1,
                "room_name(房间名称)": "种太阳??????",
                "room_id(房间编号)": 8075682,
                "date(日期)": "2020-11-01~2020-12-16"
            }
        ]
     }
     *
     *
     */
    public function list(Request $request) {
        //参数校验
        $v = app('validator')->make($request->all(), [
            'start_time' => 'required|string|date_format:Y-m-d',
            'end_time' => 'required|string|date_format:Y-m-d',
            'label_id' => 'required|numeric|exists:mysql.ln_room_label,id',
        ]);
        if ($v->fails()) {
            throw new BasicException(0, $v->errors()->first());
        }

        $list = app('repo_room')->statistic($request->input());

        return Response::sendData($list);
    }


}
